package client3;

import java.rmi.RemoteException;

import client3.HotelReservationStub.BookRoom;
import client3.HotelReservationStub.BookRoomResponse;
import client3.HotelReservationStub.CancelBooking;
import client3.HotelReservationStub.Date;
import client3.HotelReservationStub.GetAvailableRooms;
import client3.HotelReservationStub.GetAvailableRoomsResponse;
import client3.HotelReservationStub.RoomInfo;
import client3.HotelReservationStub.StayPeriod;


public class Webserviceclient3 {
	
	public static void main(String[] args) throws RemoteException {

		HotelReservationStub stub = new HotelReservationStub();

		Date checkin = new Date();
		Date checkout = new Date();
		StayPeriod period = new StayPeriod();
		checkin.setDate(15);
		checkin.setMonth(11);
		checkin.setYear(2012);

		checkout.setDate(30);
		checkout.setMonth(11);
		checkout.setYear(2012);

		period.setCheckin(checkin);
		period.setCheckout(checkout);
		//OK now i loaded some test data for the getRooms function

		//pass them in the getRooms function
		getRooms(stub, period);
		
		checkin.setDate(15);
		checkin.setMonth(11);
		checkin.setYear(2012);

		checkout.setDate(30);
		checkout.setMonth(11);
		checkout.setYear(2012);

		period.setCheckin(checkin);
		period.setCheckout(checkout);
		//OK now i loaded some test data for the BookRooms function

		bookRooms(stub,"standard",5,period);
		
		cancelBooking(stub, "e1d6590e-20c8-4a80-8a95-649db39f2173");
	}

	public static void getRooms(HotelReservationStub stub, StayPeriod period) throws RemoteException{
			
		GetAvailableRooms getrooms = new GetAvailableRooms();

		getrooms.setPeriod(period);
		GetAvailableRoomsResponse responserooms = stub.getAvailableRooms(getrooms);
		
		RoomInfo[] roomsInfo = responserooms.get_return();
		
		for (RoomInfo room : roomsInfo){
			if (room != null) {
				System.out.println("Available Room: " + room.getRate());
			}
		}

	}
	
	public static void bookRooms(HotelReservationStub stub, String type, int amount, StayPeriod period) throws RemoteException{
		
		BookRoom bookrooms = new BookRoom();
		
		bookrooms.setType(type);
		bookrooms.setAmount(amount);
		bookrooms.setPeriod(period);
		
		BookRoomResponse responsebooks = stub.bookRoom(bookrooms);
		System.out.println("Book Rooms: " + responsebooks.get_return());
	}

	public static void cancelBooking(HotelReservationStub stub, String id) throws RemoteException{
		
		CancelBooking cancel = new CancelBooking();
		stub.cancelBooking(cancel);
		System.out.println("Booking with id: " + id + "is canceled");
	}
}
